package com.epower.web.action.epoweruser;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;
import com.epower.base.BaseAction;
import com.epower.bo.epoweruser.EpowerUserService;
import com.epower.dataobject.EpowerUserDO;


@Scope("prototype")
@Component()
public class EpowerUserAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	/*** 查询对象 ***/
	private EpowerUserDO query;

	/*** 对象集合 ***/
	private List<EpowerUserDO> epowerUserList;

	/*** BO ***/
	private EpowerUserService epowerUserBO;

	/*** 主键 ***/
	private Integer id;

	/*** 查询对象 ***/
	private EpowerUserDO epowerUser;

	/*** 当前action所在的namespace ***/
	private String namespace = "epoweruser";
	/*** 当前action对应的module ***/
	private String moduleName = "EpowerUser";

	/***
	 * 列表视图
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listEpowerUser() throws Exception {
		// 初始化查询条件
		if (query == null) {
			query = new EpowerUserDO();
		}
		// 查询列表
		epowerUserList = epowerUserBO.getEpowerUserListPageByOption(query);
		pages = this.getPagesList(query.getToPage(), query.getTotalPage());
		return SUCCESS;
	}

	/***
	 * 编辑视图
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viewEditEpowerUser() throws Exception {
		epowerUser = epowerUserBO.getEpowerUserById(id);
		return SUCCESS;
	}

	/***
	 * 编辑操作
	 * 
	 * @return
	 * @throws Exception
	 */

	public String editEpowerUser() throws Exception {
		if (!epowerUserBO.updateEpowerUserByOption(epowerUser)) {
			addActionMessage("编辑失败");
			return SUCCESS;
		}
		addActionMessage("编辑成功");
		return SUCCESS;
	}

	/***
	 * 删除操作
	 * 
	 * @return
	 * @throws Exception
	 */
	public String deleteEpowerUser() throws Exception {
		if (!epowerUserBO.deleteEpowerUserById(id)) {
			addActionMessage("删除失败");
			return SUCCESS;
		}
		addActionMessage("删除成功");
		return SUCCESS;
	}

	/***
	 * 添加视图
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viewAddEpowerUser() throws Exception {
		return SUCCESS;
	}

	/***
	 * 添加操作
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addEpowerUser() throws Exception {
		if (epowerUserBO.addEpowerUser(epowerUser) == null) {
			addActionMessage("添加失败");
			return SUCCESS;
		}
		addActionMessage("添加成功");
		return SUCCESS;
	}

	/*** setter getter start ***/
	public EpowerUserDO getQuery() {
		return query;
	}

	public void setQuery(EpowerUserDO query) {
		this.query = query;
	}

	public List<EpowerUserDO> getEpowerUserList() {
		return epowerUserList;
	}

	public void setEpowerUserList(List<EpowerUserDO> epowerUserList) {
		this.epowerUserList = epowerUserList;
	}

	public EpowerUserService getEpowerUserBO() {
		return epowerUserBO;
	}

	@Resource
	public void setEpowerUserBO(EpowerUserService epowerUserBO) {
		this.epowerUserBO = epowerUserBO;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public EpowerUserDO getEpowerUser() {
		return epowerUser;
	}

	public void setEpowerUser(EpowerUserDO epowerUser) {
		this.epowerUser = epowerUser;
	}

	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	/*** setter getter end ***/
}
